$(window).resize(function() {
	init_responsive();
});
function init_responsive(){
	$screensize = $(window).width();
	var mobile_timer = false;
	if(navigator.userAgent.match(/iPhone/i)) {
		$('#viewport').attr('content','width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0');
		$(window).bind('gesturestart',function () {
			clearTimeout(mobile_timer);
			$('#viewport').attr('content','width=device-width,minimum-scale=1.0,maximum-scale=1.0');
		}).bind('touchend',function () {
			clearTimeout(mobile_timer);
			mobile_timer = setTimeout(function () {
				$('#viewport').attr('content','width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0');
			},1000);
		});
	}
	if ($screensize >=768) {
		if(first_time_lg==false){
			first_time_lg = true;
			$('.news-footer ul').css('display','');
			$('.news-footer .visible-sm.pull-right.pull-down-sm').removeClass('active');
			$('#menu-kk-top').removeClass('in').removeClass('collapse').addClass('collapse');

			$("#menu-kk-top > li").unbind('mouseover').bind('mouseover', function(){
				$("#menu-kk-top > li").not(":eq("+$(this).index()+")").find(".sub-menu").hide();
				$(this).find(".sub-menu").fadeIn(200);	
			});
			$("#menu-kk-top > li").unbind('mouseout').bind('mouseout', function(){});

			$(".header").unbind('mouseleave').bind('mouseleave', function(){
				var current = $("#menu-kk-top .current");
				
				$("#menu-kk-top > li").not(":eq("+current.index()+")").find(".sub-menu").hide();
				current.find(".sub-menu").fadeIn(200);			
			});

			$(".tab-product > div").unbind('click').bind('click', function () {
				var id = $(this).attr('id');
				$('.tab-product > div').removeClass("active");  
				$('.tab-product-content > div').css("display",'none'); 
				$(this).addClass("active"); 
				$('#c'+id).fadeIn('medium');
			});

			$(".tab.hidden-sm > div > div").unbind('click').bind('click', function () {
				var id = $(this).attr('id');
				$('.tab.hidden-sm > div > div').removeClass("active");  
				$('.ctab').css("display",'none'); 
				$(this).addClass("active"); 
				$('#c'+id).fadeIn('medium');
			});
			
			if(first_time==false){
				$('.tab-product #tab1').click();
				$('.tab.hidden-sm #tab1').click();
				first_time = true;
			}

			// set news-footer-item
			var maxHeight = -1;
			$('.news-footer-item').each(function() {
				$(this).attr('style','');
				if ($(this).height() > maxHeight)
					maxHeight = $(this).height();
			});

			$('.news-footer-item').each(function() {
				$(this).height(maxHeight);
			});

			// set news-item
			var maxHeight = -1;
			$('.news-item').each(function() {
				$(this).attr('style','');
				if ($(this).height() > maxHeight)
					maxHeight = $(this).height();
			});

			$('.news-item').each(function() {
				$(this).height(maxHeight);
			});

			// set tab-item
			var maxHeight = -1;
			$('.tab.hidden-sm > div > div').each(function() {
				$(this).attr('style','');
				if ($(this).height() > maxHeight)
					maxHeight = $(this).height();
			});

			$('.tab.hidden-sm > div > div').each(function() {
				$(this).height(maxHeight+20);
			});
		}
		
		if ($screensize >=768 && $screensize <=991) $('.menu-kk').css('width','100%');
		else $('.menu-kk').css('width','');
		
		if ($screensize >=768 && $screensize <=991){ 
			setTimeout(function(){
				if($('.scroll-sm-product').length!=0&&$('.scroll-sm-product .mCustomScrollBox').length==0){
					$(".scroll-sm-product").mCustomScrollbar({
						theme:"light",
						horizontalScroll:true
					});
					$('.scroll-sm-product').fadeIn();
				}
			},1000);
		}else{ 
			if($('.scroll-lg-product').length!=0&&$('.scroll-lg-product .mCustomScrollBox').length==0){
				$(".scroll-lg-product").mCustomScrollbar({
					theme:"light"
				});
				$('.scroll-lg-product').fadeIn();
			}
		}
		
	}else{
		if(first_time_sm==false){
			first_time_sm = true;
                $('.shop-imgs').unbind('click').bind('click',function(){  
                   document.location.href = $(this).attr('data'); 
					});
			$("#menu-kk-top > li").unbind('mouseover');
			$(".header").unbind('mouseleave');
			$('.menu-kk').css('width','');
			$('.menu-item').each(function(){
			if($(this).find('.visible-sm.pull-right.pull-down').length==0){
				$('<span class="visible-sm pull-right pull-down"></span>').insertBefore($(this).find('.sub-menu').prev());
			}
			});
			$('.news-footer-item').each(function() {
				$(this).height('');
			});
			$('.navbar-toggle').unbind('click').bind('click', function(){
				if(!$('.navbar-responsive-collapse').hasClass('in')){
					$('.header.event + div').css('zIndex','8');
					$('.thumb-product').css('zIndex','8');
				}else{
					$('.header.event + div').css('zIndex','10');
					$('.thumb-product').css('zIndex','10');
				}
			});
			$(".menu .pull-down").unbind('click').bind('click', function () {
				$(this).toggleClass("active");  
				$(this).parent().find(".sub-menu").slideToggle('medium');
			});
			$(".news-footer-item .pull-down-sm").unbind('click').bind('click', function () {
				$(this).toggleClass("active");  
				$(this).parent().parent().find("ul").slideToggle('medium');
			});
			$(".tab-content .visible-sm > div").unbind('click').bind('click', function () {
				var id = $(this).attr('id');
				$(this).toggleClass("active");  
				$('#c'+id).slideToggle('medium');
			});
			$(".tab-product-content .visible-sm > div").unbind('click').bind('click', function () {
				var id = $(this).attr('id');
				$(this).toggleClass("active");  
				$('#c'+id).slideToggle('medium');
			});
	    }
	}
	if(first_time_tt==false){
		first_time_tt = true;
		$('.menu-item a').each(function(){
			var href_menu = $(this).attr('href');
			if(!$(this).prev().hasClass('pull-down')){
				$(this).parent().click(function(){
					document.location.href = href_menu;
				});
			}
		});
		$('.size').unbind('click').bind('click', function(){
			var is_same_choose = false;
			for(var i=0;i<$('.size').length;i++){
				if($(this).attr('itemid')==$($('.size')[i]).attr('itemid') && $($('.size')[i]).hasClass('active'))
				is_same_choose = true;
			}
			$('.size').removeClass('active');
			if(is_same_choose==false) $(this).addClass('active');
			// DO SOMETHING
		});
		$('.list-product.visible-md .col-sm-6').addClass('col-sm-4').removeClass('col-sm-6');
	}
}

var first_time = false;
var first_time_sm = false;
var first_time_md = false;
var first_time_lg = false;
var first_time_tt = false;
$('body').waitForImages(function() {
    init_responsive();
});

function changefutureimg($imglink){
    jQuery('#mainfutured').attr('src',$imglink); 
    
}

